package com.atguigu.gmall;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;
import java.util.concurrent.Future;

/**
 * Date:2021/3/21
 * Author:csw
 * Description:
 */
public class MyProducer {
    private static KafkaProducer producer;
    static {
        producer=getProducer();
    }



    public static KafkaProducer<String,String> getProducer(){
        Properties properties = new Properties();
        properties.put("bootstrap.servers","hadoop102:9092,hadoop103:9092,hadoop104:9092");
        properties.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
        properties.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer");

        KafkaProducer<String, String> producer = new KafkaProducer<>(properties);
        return  producer;
    }

    public static void send(String topic , String value){
        producer.send(new ProducerRecord<String, String>(topic, value));

    }

}
